package chapter05;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author chisheng
 * @since 2021-11-11
 */
public class EventClient {

    public static void main(String[] args) {
        EventQueue eventQueue = new EventQueue();

        new Thread(() -> {
            while (true) {
                eventQueue.offer(new EventQueue.Event());
            }
        }, "Producer-01").start();

        new Thread(() -> {
            while (true) {
                eventQueue.offer(new EventQueue.Event());
            }
        }, "Producer-02").start();

        new Thread(() -> {
            while (true) {
                try {
                    eventQueue.take();
                    TimeUnit.SECONDS.sleep(new Random().nextInt(10));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "Consumer").start();
    }

}
